package com.bstek.uflo.form.command;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.hibernate.jdbc.Work;

import com.bstek.uflo.command.Command;
import com.bstek.uflo.env.Context;
import com.bstek.uflo.form.view.table.dialect.Dialect;

/**
 * @author Jacky.gao
 * @since 2013年11月7日
 */
public class GetDataTypeCommand implements Command<List<String>> {
	public List<String> execute(Context context) {
		final List<String> dataTypes=new ArrayList<String>();
		final Collection<Dialect> dialects=context.getApplicationContext().getBeansOfType(Dialect.class).values();
		context.getSession().doWork(new Work(){
			public void execute(Connection connection) throws SQLException {
				for(Dialect dialect:dialects){
					if(dialect.support(connection)){
						dataTypes.addAll(dialect.getDataTypes());
						break;
					}
				}
			}
		});
		return dataTypes;
	}
}
